import React, { Dispatch, SetStateAction, useState } from "react"
import { getItemCount } from "../../hooks/cart"

export const CountContext = React.createContext<
    [number, Dispatch<SetStateAction<number>>]
>([0, () => null])

const CartItemCount = ({ children }: { children: JSX.Element | JSX.Element[] }) => {
    const [count, setCount] = useState(getItemCount())
    return (
        <CountContext.Provider value={[count, setCount]}>{children}</CountContext.Provider>
    )
}

export default CartItemCount
